package com.luncheng.mcp.core.router;

import org.springframework.web.servlet.function.HandlerFunction;
import org.springframework.web.servlet.function.RouterFunction;
import org.springframework.web.servlet.function.ServerRequest;
import org.springframework.web.servlet.function.ServerResponse;

import java.util.Optional;

public class MutableRouterFunction implements RouterFunction<ServerResponse> {

    private volatile RouterFunction<ServerResponse> delegate = request -> Optional.empty();

    public void setDelegate(RouterFunction<ServerResponse> delegate) {
        this.delegate = delegate;
    }

    @Override
    public Optional<HandlerFunction<ServerResponse>> route(ServerRequest request) {
        // 把请求转发给当前的 delegate
        return delegate.route(request);
    }
}